import 'package:flutter/material.dart';

import 'friend.dart';
import 'home.dart';
import 'me.dart';
import 'message.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  MyApp() : super();
  _MainAppState createState() => _MainAppState();
}

class _MainAppState extends State<MyApp> {
  int _pageIndex = 0;
  List _pageList = [
    {"name": "首页", "page": HomePage()},
    {"name": "朋友", "page": FriendPage()},
    null,
    {"name": "消息", "page": MessagePage()},
    {"name": "我", "page": MePage()},
  ];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: getAppBar(),
        body: this._pageList[_pageIndex]["page"],
        bottomNavigationBar: Container(
          color: Colors.black,
          height: 60,
          child: Row(
            children: List<Widget>.generate(5, (index) {
              if (index == 2) {
                return InkWell(
                  child: Icon(
                    Icons.add_to_queue_rounded,
                    color: Colors.white,
                    size: 30,
                  ),
                  onTap: () {},
                );
              } else {
                return InkWell(
                  child: Container(
                    height: double.infinity,
                    width: 50,
                    child: Center(
                      child: Text(
                        _pageList[index]["name"],
                        style: TextStyle(
                          color: tapColor(index),
                          fontSize: 20,
                        ),
                      ),
                    ),
                  ),
                  onTap: () {
                    setState(() {
                      _pageIndex = index;
                    });
                  },
                );
              }
            }),
            mainAxisAlignment: MainAxisAlignment.spaceAround,
          ),
        ),
      ),
    );
  }

  getAppBar() {
    if (_pageIndex != 0) {
      return AppBar(
        title: Text('Tiktok'),
        backgroundColor: Colors.black,
      );
    }
  }

  tapColor(i) {
    if (_pageIndex == i) {
      return Colors.white;
    } else {
      return Colors.white70;
    }
  }
}
